Exemplo n.º 1
0
 /// <summary>
 /// Tries to create a view model from a given stream.
 /// </summary>
 /// <param name="text">Display text or filename of the resource for the resulting <see cref="DataViewNode"/>.</param>
 /// <param name="stream">Stream containing resource data.</param>
 /// <param name="viewModel">The resulting view model for the given resource.</param>
 /// <returns>Whether or not the operation succeeded.</returns>
 public static bool TryCreate(string text, Stream stream, out DataViewNode viewModel)
 {
     return(TryCreate(text, stream, null, out viewModel));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to create a view model from a given stream.
        /// </summary>
        /// <param name="text">Display text or filename of the resource for the resulting <see cref="DataViewNode"/>.</param>
        /// <param name="stream">Stream containing resource data.</param>
        /// <param name="viewModel">The resulting view model for the given resource.</param>
        /// <returns>Whether or not the operation succeeded.</returns>
        public static bool TryCreate(string text, Stream stream, object[] extraArguments, out DataViewNode viewModel)
        {
            // check if the given text is likely a filename
            string filename = null;

            if (stream is FileStream fileStream)
            {
                filename = fileStream.Name;
            }
            else
            {
                if (Path.HasExtension(text))
                {
                    filename = text;
                }
            }

            // try get module for importing
            if (!ModuleImportUtilities.TryGetModuleForImport(stream, out var module, filename))
            {
                // fallback
                viewModel = new StreamViewNode(text, stream);
                viewModel.Initialize();
                return(true);
            }

            // import resource w/ module
            var resource = module.Import(stream, filename);

            // try to create a view model
            if (!TryCreate(text, resource, module.ModelType, extraArguments, out viewModel))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Tries to create an view model from a given file.
 /// </summary>
 /// <param name="filepath">File path pointing to a resource to import.</param>
 /// <param name="viewModel">The resulting view model for the given resource.</param>
 /// <returns>Whether or not the operation succeeded.</returns>
 public static bool TryCreate(string filepath, out DataViewNode viewModel)
 {
     return(TryCreate(filepath, ( object[] )null, out viewModel));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Tries to create a view model from a given stream.
        /// </summary>
        /// <param name="text">Display text or filename of the resource for the resulting <see cref="DataViewNode"/>.</param>
        /// <param name="resource">The resource for which to create a view model for.</param>
        /// <param name="viewModel">The resulting view model for the given resource.</param>
        /// <returns>Whether or not the operation succeeded.</returns>
        public static bool TryCreate(string text, object resource, Type type, object[] extraArguments, out DataViewNode viewModel)
        {
            if (!sCreatorByType.TryGetValue(type, out var adapterCreator))
            {
                // check if the type is a constructed generic type
                if (type.IsConstructedGenericType)
                {
                    // try looking up the unbound generic type definition
                    var typeGenericUnbound = type.GetGenericTypeDefinition();
                    if (!sCreatorByType.TryGetValue(typeGenericUnbound, out adapterCreator))
                    {
                        viewModel = null;
                        return(false);
                    }
                }
                else
                {
                    viewModel = null;
                    return(false);
                }
            }

            viewModel = adapterCreator(text, resource, extraArguments);
            return(true);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Tries to create a view model from a given stream.
 /// </summary>
 /// <param name="text">Display text or filename of the resource for the resulting <see cref="DataViewNode"/>.</param>
 /// <param name="resource">The resource for which to create a view model for.</param>
 /// <param name="viewModel">The resulting view model for the given resource.</param>
 /// <returns>Whether or not the operation succeeded.</returns>
 public static bool TryCreate(string text, object resource, object[] extraArguments, out DataViewNode viewModel)
 {
     return(TryCreate(text, resource, resource.GetType(), extraArguments, out viewModel));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Tries to create a view model from a given stream.
 /// </summary>
 /// <param name="text">Display text or filename of the resource for the resulting <see cref="DataViewNode"/>.</param>
 /// <param name="resource">The resource for which to create a view model for.</param>
 /// <param name="viewModel">The resulting view model for the given resource.</param>
 /// <returns>Whether or not the operation succeeded.</returns>
 public static bool TryCreate(string text, object resource, out DataViewNode viewModel)
 {
     return(TryCreate(text, resource, null, out viewModel));
 }
Exemplo n.º 7
0
 public DataViewNodePropertyChangedEventArgs(DataViewNode node, string propertyName)
 {
     Node         = node;
     PropertyName = propertyName;
 }